import * as Request from '../utils/Request.jsx';
const { routerRedux } = dva.router;
const { message } = antd;

export default {
    namespace: 'login',
    state: {
    },
    effects: {
        *login({ payload }, { call, put }) {// 登陆
            const { code, msg, data } = yield call(Request.post, 'login', payload);
            if(code !== 0) {
                return message.error(msg);
            }
            yield put(routerRedux.push({ pathname: '/index' }));
            yield put({ type: 'app/loginSuccess', payload: { data } });
        },
        *reloadLoginData({ payload }, { call, put }) {// 重新加载登陆数据
            const { data } = yield call(Request.get, 'login', payload);
            yield put({ type: 'app/loginSuccess', payload: { data } });
            history.go(-1);
        }
    }
};